
# raise关键字
"""
1. 概念 ： 主动抛出异常，使用raise
2. 格式 ：raise 异常类
"""

import pymysql
pymysql.connect()

def read_file(filename):
    f = None
    content = None
    try:

        f = open(filename)
        content = f.read()
        print(content)
        return content

    except FileNotFoundError as e:
        print("读取文件不存在，请检查:{}".format(e))

    # except UnicodeDecodeError as e:
    #     print("文件编码不正确，请检查:{}".format(e))

    except Exception as e:
        raise e

    finally:  # 必须走这段代码
        if f:
            f.close()


if __name__ == '__main__':
    read_file('a.txt')